package com.molyfun.parents.utils;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:26/02/2018.
 */

public class UrlUtils {

    public static boolean isExpired(String url) {
        try {
            String[] times = url.split("&t=");
            if(times.length < 2){
                return true;
            }
            String time = times[1];
            long s;
            if (time.startsWith("0x")) {
                s = Long.parseLong(time.substring(2), 16);
            } else {
                s = Long.parseLong(time, 16);
            }
            long timeStampSec = System.currentTimeMillis() / 1000;
            if (s < timeStampSec) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            return true;
        }
    }

    public static String getNewUrl(String url) {
        try {
            String[] urls = url.split("\\?");
            if (urls.length == 1) {
                return url;
            }
            String[] ss = urls[1].split("&");
            if (ss.length == 2) {
                return urls[0];
            }
            if (ss.length == 3) {
                return urls[0] + "?" + ss[0];
            } else {
                return url;
            }
        } catch (Exception e) {
            return url;
        }
    }
}
